package com.deng.activity.util;

import com.deng.activity.vo.ActivityDayVo;

import java.util.Calendar;

/**
 * 活动时间相关util
 */
public class ActivityUtil {

    /**
     * 获取ActivityDayVo
     * @param calendar
     * @return
     */
    public static ActivityDayVo calendarToActivityDayVo(Calendar calendar) {
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        return ActivityDayVo.builder()
                .year(onesDigitToDoubleStr(year))
                .month(onesDigitToDoubleStr(month))
                .day(onesDigitToDoubleStr(day))
                .build();
    }

    public static String CalendarToWeekStr(Calendar calendar) {
         return switch (calendar.get(Calendar.DAY_OF_WEEK)) {
             case Calendar.SUNDAY -> "周日";
             case Calendar.MONDAY -> "周一";
             case Calendar.TUESDAY -> "周二";
             case Calendar.WEDNESDAY -> "周三";
             case Calendar.THURSDAY -> "周四";
             case Calendar.FRIDAY -> "周五";
             case Calendar.SATURDAY -> "周六";
             default -> "异常";
        };
    }

    /**
     * 将一个个位数转为两个数表示（即将1 转为 01）
     * 如果传入的参数大于等于10则按String方式原样返回
     * 返回String表示
     * @param number
     * @return
     */
    private static String onesDigitToDoubleStr(int number) {
        String str = String.valueOf(number);
        return str.length() == 1 ? "0".concat(str) : str;
    }


}
